package com.qmerak.common;

import java.util.Map;

import com.qmerak.entity.MemberEntity;
import com.qmerak.entity.OrgEntity;
import com.qmerak.entity.PostUnitEntity;
import com.qmerak.service.IOrgService;
import com.qmerak.service.IPostUnitService;

/**
 * @author Shaohong•Cheng
 * @mail shaohong726@126.com
 * @date 2013-5-21
 * @project WebTest
 */
public class ViewUtil {

	public static boolean isZhuXi(MemberEntity entity) {
		if (SysConstants.SYS_MANAGER_LOGINNAME.equals(entity.getLoginName())) {
			return true;
		}
		boolean result = false;
		String roleString = entity.getRoles();
		if (null != roleString) {
			String[] strings = roleString.split(",");
			for (String string : strings) {
				if ("1".equals(string)) {
					result = true;
				}
			}
		}
		return result;
	}

	public static boolean isFuZhuXi(MemberEntity entity) {
		if (SysConstants.SYS_MANAGER_LOGINNAME.equals(entity.getLoginName())) {
			return true;
		}
		boolean result = false;
		String roleString = entity.getRoles();
		if (null != roleString) {
			String[] strings = roleString.split(",");
			for (String string : strings) {
				if ("2".equals(string)) {
					result = true;
				}
			}
		}
		return result;
	}

	public static boolean isLiShiZhang(MemberEntity entity) {
		if (SysConstants.SYS_MANAGER_LOGINNAME.equals(entity.getLoginName())) {
			return true;
		}
		boolean result = false;
		String roleString = entity.getRoles();
		if (null != roleString) {
			String[] strings = roleString.split(",");
			for (String string : strings) {
				if ("3".equals(string)) {
					result = true;
				}
			}
		}
		return result;
	}

	public static boolean isGanBu(MemberEntity entity) {
		if (SysConstants.SYS_MANAGER_LOGINNAME.equals(entity.getLoginName())) {
			return true;
		}
		boolean result = false;
		String roleString = entity.getRoles();
		if (null != roleString) {
			String[] strings = roleString.split(",");
			for (String string : strings) {
				if ("4".equals(string)) {
					result = true;
				}
			}
		}
		return result;
	}

	public static boolean isHuiYuan(MemberEntity entity) {
		if (SysConstants.SYS_MANAGER_LOGINNAME.equals(entity.getLoginName())) {
			return true;
		}
		boolean result = false;
		String roleString = entity.getRoles();
		if (null != roleString) {
			String[] strings = roleString.split(",");
			for (String string : strings) {
				if ("5".equals(string)) {
					result = true;
				}
			}
		}
		return result;
	}

	// orgServiceImpl,postUnitServiceImpl
	public static boolean canApplySalvage(MemberEntity entity) {
		if (SysConstants.SYS_MANAGER_LOGINNAME.equals(entity.getLoginName())) {
			return true;
		}
		Map<String, Object> services = SpringUtil.getServiceBean();
		IPostUnitService postUnitServiceImpl = (IPostUnitService) services
				.get("postUnitServiceImpl");
		IOrgService orgServiceImpl = (IOrgService) services
				.get("orgServiceImpl");
		if (null == entity.getWorkUnit() || "".equals(entity.getWorkUnit())) {
			return false;
		}
		PostUnitEntity unitEntity = postUnitServiceImpl.find(entity
				.getWorkUnit());
		OrgEntity orgEntity = orgServiceImpl.find(unitEntity.getUnionID());
		if ("1".equals(orgEntity.getOrgGrade())
				|| "2".equals(orgEntity.getOrgGrade())) {
			return true;
		}
		return false;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
